package com.example.demo.hot.example;

import java.util.Stack;

/**
 * @Classname StackExample
 * @Description
 * @Date 2023/11/8 15:57
 * @Created by jyl
 *
 * 设计模式
 */
public class StackExample {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();

        // 压入元素到堆栈
        stack.push(1);
        stack.push(2);
        stack.push(3);

        // 弹出元素
        int top = stack.pop();
        System.out.println("弹出元素: " + top);

        // 获取栈顶元素，但不弹出
        int peek = stack.peek();
        System.out.println("栈顶元素: " + peek);

        // 检查堆栈是否为空
        boolean isEmpty = stack.isEmpty();
        System.out.println("堆栈是否为空: " + isEmpty);

        // 获取堆栈的大小
        int size = stack.size();
        System.out.println("堆栈的大小: " + size);
    }
}
